package com.company.userRegister.service;

import com.company.userRegister.model.User;
import com.company.userRegister.validation.UserValidator;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

public class UserService {
    private static final Pattern EMAIL_PATTERN = Pattern.compile(
        "^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$"
    );

    private final Map<String, User> userStorage = new HashMap<>();

    public void registerUser(User user) {
        UserValidator.validateUsername(user.getUsername());
        UserValidator.validateEmail(user.getEmail());
        UserValidator.validatePassword(user.getPassword());
        if (userStorage.containsKey(user.getEmail())) {
            throw new IllegalArgumentException("该邮箱已经被注册！");
        }
        userStorage.put(user.getEmail(), user);
    }
}
